#include "BasicDefs.h"

using namespace VoxelCore;
//////////////////////////////////////////////////////////////////////////
//boundingbox
BoundingBox::BoundingBox(const Pointlist& pts)
{
	//calculate the bbox of pts
	Pointlist::const_iterator pt_itr = pts.begin();
	Max = pts[0];
	Min = pts[0];
	for (; pt_itr != pts.end(); pt_itr++)
	{
		if ((*pt_itr).x > Max.x)
			Max.x = (*pt_itr).x;
		if ((*pt_itr).y > Max.y)
			Max.y = (*pt_itr).y;
		if ((*pt_itr).z > Max.z)
			Max.z = (*pt_itr).z;

		if ((*pt_itr).x < Min.x)
			Min.x = (*pt_itr).x;
		if ((*pt_itr).y < Min.y)
			Min.y = (*pt_itr).y;
		if ((*pt_itr).z < Min.z)
			Min.z = (*pt_itr).z;
	}
}

Vector3d BoundingBox::GetSize()
{
	return Vector3d(Max.x - Min.x, Max.y - Min.y, Max.z - Min.z);
}

double BoundingBox::GetMaxSize()
{
	return max(max(Max.x - Min.x, Max.y - Min.y), Max.z - Min.z);
}
